/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.sdkj.dspservice.modules.demand.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.sdkj.dspservice.common.base.dao.CrudDao;
import com.sdkj.dspservice.modules.demand.entity.Demand;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 需求DAO接口
 * @author tm
 */
public interface DemandDao extends CrudDao<Demand> {

    /**
     * 获取最大编码
     * @return
     */
    @Select("select max(code) from demand_demand")
    String getMaxCode();

    /**
     * 获取当前登录用户待办数量
     * @return
     */
    @Select("select count(*) from demand_demand where now_user_id = #{currentUserId} and flow_status not in ('0', '6')")
    int getCountToDo(String currentUserId);

    /**
     * 关联查询
     * @param wrapper
     * @return
     */
    @Select("select a.*,cu.name as \"createByUser.name\", t.name as \"type.name\",nu.name as \"nowUser.name\" " +
            "from demand_demand a " +
            "left join sys_user cu on cu.id = a.create_by " +
            "left join sys_user nu on nu.id = a.now_user_id " +
            "left join demand_type t on t.id = a.type_id " +
            "${ew.customSqlSegment}"
    )
    IPage<Demand> pageLink(IPage<Demand> page, @Param(Constants.WRAPPER) Wrapper<Demand> wrapper);

}
